home *** CD-ROM | disk | FTP | other *** search
- Path: inferno.mpx.com.au!news
- From: Malcolm Smith <mjsmith@mpx.com.au>
- Newsgroups: comp.lang.c
- Subject: Re: fopen not working
- Date: 16 Feb 1996 07:19:57 GMT
- Organization: Microplex Pty Ltd
- Message-ID: <4g1b6t$2ra@inferno.mpx.com.au>
- References: <4fjnj1$4q@fig.leba.net>
- NNTP-Posting-Host: dialup-211.mpx.com.au
-
- fweaver@leba.net wrote:
- >
- > Good evening to all C programers
- >
- > I have a problem I thought someone might be able to shed some light on
- > for me. Below is some of the code I wrote for an install program.
- >
- >
- > #include<stdio.h>
- > #include<conio.h>
- > char buf[125],stwd[110],trwd[110],*pt,*pt1;
- > int i,vr,vd;
- > FILE *in, *out;
- > main()
- > { [snip]
- >
- > instlfile("trkr.cf_","trkr.cfg");
- > instlfile("maplvl3.da_","maplvl3.dat");
- > instlfile("atpctrkr.do_","atpctrkr.doc");
- > instlfile("readme.1s_","readme.1st");
- > instlfile("file_id.di_","file_id.diz");
- >
- > [snip]
- >
- > if((in=fopen(buf,"r"))!=NULL)
- > { do{ fgets(buf,120,in);
- > pt= (char *)strstr(buf,"XXXXX");
- > if(pt!=NULL){ fclose(out); pt=pt+5;if((out=fopen(pt,"w"))==NULL)printf("ERROR");
-
- ---------
- Without testing the code my best guess is that on the first pass
- through the program detects the "XXXXX" and hence tries to close
- the previous file. But there isn't one open yet.
- ---------
-
- > else{printf("\nInstalling %s",pt);continue; }}
- > fputs(buf,out);
- > }while(feof(in)==0);
- > }
- > }
-
- > [snip]
- >
- > instlfile(char f[15],char s[15])
- > { sprintf(buf,"%s%s",stwd,f);
- > if((in=fopen(buf,"rb"))==NULL){close(in);return(0);}
-
- ----------
- In the above line use fclose() for the corresponding fopen().
- ----------
-
- > if((out=fopen(s,"wb"))!=NULL)printf("\nInstalling %s",s);
- > while((i=fgetc(in))!=EOF){fputc(i,out);}
- > _fcloseall();
- > }
-
-
-
- Regards,
-
- Mal
-